<?php
/**
 * 配音接口
 */
require_once dirname(dirname(__DIR__))."/common.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\UserMaterial;
if(empty($_REQUEST['type_sub'])){
    Response::output(-1,"缺少参数");
}
$type_sub=$_REQUEST['type_sub'];

//先从缓存里读取数据
$redis = SysResource::getRedis();
$redis_cache_key=REDIS_PREFIX."DUB_TYPE_LIST_".$type_sub;
$redis_cache_data=$redis->get($redis_cache_key);

if($redis_cache_data){

    //读取redis缓存
    $data=json_decode($redis_cache_data);
    Response::output(0,"查询成功1",$data,count($data));
}else {

    //查询数据库

    //分页
    $page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
    $page = $page > 0 ? $page : 1;
    $pageSize =10;
    //实例化数据库
    $db = SysResource::getDB(false);
    $UserMaterial = new UserMaterial($db);
    $da1=$UserMaterial->type_sub_list($page,$pageSize,$type_sub);
    if(empty($da1)){
        Response::output(0,"查询成功",[],0);
    }else{
        foreach($da1['data'] as $k=>&$v){
            if(empty($v['video_share_pic'])){
                $v['share_pic']="";
            }else{
                $v['share_pic']=$v['video_share_pic'];
            }
        }
        $redis->setex($redis_cache_key,15,json_encode($da1['data']));
        Response::output(0,"查询成功",$da1['data'],count($da1['data']));
    }

}

